package com.preskool.service.impl;

import com.preskool.mapper.*;
import com.preskool.po.*;
import com.preskool.service.DashboardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author ZhaoBo
 * @description: 仪表板
 * @date 2021/1/7  14:38
 */
@Service
public class DashboardServiceImpl implements DashboardService {
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private TeacherMapper teacherMapper;
    @Resource
    private DepartmentsMapper departmentsMapper;
    @Resource
    private SalaryMapper salaryMapper;
    @Resource
    private ExpensesMapper expensesMapper;
    @Resource
    private ActivityFeesMapper activityFeesMapper;
    @Resource
    private EventsMapper eventsMapper;

    /**
     * 查询学生总数量
     * @return
     */
    @Override
    public int findStudentCount() {
        StudentExample example = new StudentExample();
        int count = (int) studentMapper.countByExample(example);
        return count;
    }

    /**
     * 查询老师总数
     * @return
     */
    @Override
    public int findTeacherCount() {
        TeacherExample example = new TeacherExample();
        int count = (int) teacherMapper.countByExample(example);
        return count;
    }

    /**
     * 查部门数量
     * @return
     */
    @Override
    public int findDepartmentCount() {
        DepartmentsExample example = new DepartmentsExample();
        int count = (int) departmentsMapper.countByExample(example);
        return count;
    }

    /**
     * 平均工资
     * @return
     */
    @Override
    public double findSalaryAvg() {
        Double amount = salaryMapper.selectAvgAmount();
        return amount;
    }

    /**
     * 每月收入
     * @param start
     * @param end
     * @return
     */
    @Override
    public Double[] findPurchaseByDate(String start, String end) {
        Double[] myList = new Double[12];
        for(int i = 1;i <= 12 ;i ++){
            String sta = "2020-0"+i+"-1";
            String end1 = "2020-0"+i+"-31";
            List<Expenses> expensess = expensesMapper.selectPurchaseByDate(sta, end1);
            Double add = 0.0;
            for (Expenses expens : expensess) {
                add += expens.getAmount();
            }
            myList[i-1] = add;
        }
        return myList;
    }

    /**
     * 每月支出
     * @param start
     * @param end
     * @return
     */
    @Override
    public Double[] findPurchaseByFees(String start, String end) {
        Double[] myList = new Double[12];
        for(int i = 1;i <= 12 ;i ++){
            String sta = "2020-0"+i+"-1";
            String end1 = "2020-0"+i+"-31";
            List<ActivityFees> activityFees = activityFeesMapper.selectPurchaseByFees(sta, end1);
            Double add = 0.0;
            for (ActivityFees activityFee : activityFees) {
                add += activityFee.getAmount();
            }
            myList[i-1] = add;
        }
        return myList;
    }

    /**
     * 每年男生人数
     * @return
     */
    @Override
    public int[] findStudentByGenderNan() {
        int[] myList = new int[11];

        for(int i = 10;i <= 20 ;i ++){
            String sta = "20"+i+"-01-01";
            String end1 = "20"+i+"-12-31";
            Integer students = studentMapper.selectStudentByNan(sta,end1);
            myList[i-10] =students;
        }
        return myList;
    }

    /**
     * 每年女生人数
     * @return
     */
    @Override
    public int[] findStudentByGenderNv() {
        int[] myList = new int[11];

        for(int i = 10;i <= 20 ;i ++){
            String sta = "20"+i+"-01-01";
            String end1 = "20"+i+"-12-31";
            Integer students = studentMapper.selectStudentByNv(sta,end1);
            myList[i-10] =students;
        }
        return myList;
    }

    /**
     * 查询全部事件
     * @param id
     * @return
     */
    @Override
    public List<Events> findEvents() {
        List<Events> events = eventsMapper.selectAll();
        return events;
    }
}
